package compare;

import java.util.Comparator;

class AgeSec implements Comparator<Student> {

    @Override
    public int compare(Student o1, Student o2) {
        if(o1. getAge()== o2.getAge()) {
            return 0;
        }else if(o1.getAge()>o2.getAge()){
            return 1;
        }
            return -1;
    }
}

public class Student {
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

//    @Override
//    public int compareTo(Student o) {
//        if (this.age == o.age) {
//            return 0;
//        }
//        if(this.age>o.age){
//            return 1;
//        }else {
//            return -1;
//        }
//    }
//    @Override
//    public boolean equals(Object o){
//        if(this==o){
//            return true;
//        }
//        if(o==null || !(o instanceof Student)){
//            return false;
//        }
//        //o一定不为空且是Studen的对象
//        Student stu=(Student) o;
//        return this.name.equals(stu.name);
//    }
}
